package com.ruoyi.web.area.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.area.domain.Continents;
import com.ruoyi.web.area.service.IContinentsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.area.domain.Country;
import com.ruoyi.web.area.service.ICountryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 国家管理Controller
 *
 * @author hjy
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/area/country")
public class CountryController extends BaseController
{
    @Autowired
    private ICountryService countryService;

    @Autowired
    private IContinentsService continentsService;

    /**
     * 查询国家管理列表
     */
    @PreAuthorize("@ss.hasPermi('area:country:list')")
    @GetMapping("/list")
    public TableDataInfo list(Country country)
    {
        startPage();
        List<Country> list = countryService.selectCountryList(country);
        return getDataTable(list);
    }

    /**
     * 查询大洲列表
     */
    @PreAuthorize("@ss.hasPermi('area:country:list')")
    @GetMapping("/getContinentList")
    public AjaxResult getContinentList()
    {
        List<Continents> continentsList = continentsService.selectContinentsList(new Continents());
        return AjaxResult.success(continentsList);
    }


    /**
     * 导出国家管理列表
     */
    @PreAuthorize("@ss.hasPermi('area:country:export')")
    @Log(title = "国家管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Country country)
    {
        List<Country> list = countryService.selectCountryList(country);
        ExcelUtil<Country> util = new ExcelUtil<Country>(Country.class);
        util.exportExcel(response, list, "国家管理数据");
    }

    /**
     * 获取国家管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('area:country:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(countryService.selectCountryById(id));
    }

    /**
     * 新增国家管理
     */
    @PreAuthorize("@ss.hasPermi('area:country:add')")
    @Log(title = "国家管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Country country)
    {
        return toAjax(countryService.insertCountry(country));
    }

    /**
     * 修改国家管理
     */
    @PreAuthorize("@ss.hasPermi('area:country:edit')")
    @Log(title = "国家管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Country country)
    {
        return toAjax(countryService.updateCountry(country));
    }

    /**
     * 删除国家管理
     */
    @PreAuthorize("@ss.hasPermi('area:country:remove')")
    @Log(title = "国家管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(countryService.deleteCountryByIds(ids));
    }
}
